#include <iostream>

template <typename T>
class Singleton
{
private:
    static T *instance;

public:
    static T *getInstance()
    {
        if (instance == nullptr)
        {
            instance = new T();
        }
        return instance;
    }

    ~Singleton()
    {
        if (instance != nullptr)
            delete instance;
    }
};

int *Singleton<int>::instance = nullptr;

class SingletonFloat
{
private:
    // only works after C++17
    inline static float *instance;

public:
    static float *getInstance()
    {
        if (instance == nullptr)
        {
            instance = new float();
        }
        return instance;
    }
};

int main()
{
    auto inst1 = Singleton<int>::getInstance();
    *inst1 = 5;
    auto inst2 = Singleton<int>::getInstance();
    std::cout << *inst2 << std::endl;

    auto instF1 = SingletonFloat::getInstance();
    *instF1 = 5.5f;
    auto instF2 = SingletonFloat::getInstance();
    std::cout << *instF2 << std::endl;
    return 0;
}